package com.rxyb.wechat.gateway.enums;

import com.alibaba.fastjson.JSONObject;
import com.rxyb.core.respone.IBaseCode;
import com.rxyb.core.respone.enums.CommonCode;

/**
 * 响应码
 *
 * @author duyh
 * @date 2020/5/28
 */
public enum RspCode implements IBaseCode {

    APPID_EXIST("", "APPID已存在"),//

    ;

    private final String code;
    private final String msg;

    RspCode(final String code, final String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static CommonCode fromCode(String code) {
        CommonCode[] ecs = CommonCode.values();
        for (CommonCode ec : ecs) {
            if (ec.getCode().equals(code)) {
                return ec;
            }
        }
        return null;
    }


    /*
     * 错误编码 -1、失败 0、成功
     */
    @Override
    public String getCode() {
        return code;
    }

    /*
     * 错误描述
     */
    @Override
    public String getMsg() {
        return msg;
    }

    @Override
    public String toString() {
        JSONObject object = new JSONObject();
        object.put("code", code);
        object.put("msg", msg);
        return object.toString();
    }
}
